/**
*Proyecto: Autopista V.1
*MailMail.java
*Fecha Creacion: 29 Junio del 2013
*SWITZ Software Artists Derechos Reservados R
*/
package mx.com.switz.autopista.utils.mail;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.activation.FileDataSource;
import javax.mail.Address;
import javax.mail.BodyPart;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import javax.servlet.ServletContext;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.MailSender;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;

public class MailMail {
	/**
	*Clase que permite enviar un correo electronico , a traves de ciertos paramatros, en formato HTML
	*@author Hector Silvar SWITZ Software Artists
	*/
	
	private JavaMailSenderImpl  mailSender;
	@Autowired
	private Session mailSession;
		
	/**
	 * @return the mailSender
	 */
	public JavaMailSenderImpl getMailSender() {
		return mailSender;
	}

	/**
	 * @param mailSender the mailSender to set
	 */
	public void setMailSender(JavaMailSenderImpl mailSender) {
		this.mailSender = mailSender;
	}

	/**
	 * @return the mailSession
	 */
	public Session getMailSession() {
		return mailSession;
	}

	/**
	 * @param mailSession the mailSession to set
	 */
	public void setMailSession(Session mailSession) {
		this.mailSession = mailSession;
	}
	
	/**
	 * Metodo que permite en envio de email en formato HTML
	 * @param from direccion de correo de donde se envia
	 * @param to direccion de correo a donde se manda
	 * @param subject asunto del correo
	 * @param msg curpo del mensaje de correo
	 * @throws IOException
	 */
	public void sendMail(String from, String to, String subject, String msg) throws IOException {
		try {
			MimeMessage message = mailSender.createMimeMessage();
			message.setSubject(subject);
			message.setFrom(new InternetAddress(from));
			message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
			message.setContent("<html><body><img src='http://cbtis223.com/autos/head.jpg'  /><h1>Hola!!</h1>" +
					"<img src='http://cbtis223.com/autos/footer.jpg'  /></body></html>",
					"text/html");
			mailSender.send(message);		
		} catch (MessagingException e) {
			// TODO Auto-generated catch blocker
			e.printStackTrace();
		}
		
	}
	
	
	
}
